/**
 * Created by 刘柘林 on 2016/12/11.
 */
$(document).ready(function(){
    var _url = window.location.pathname + window.location.search;
    $.ajax({
        url : _url,
        dataType : 'json',
        type : 'post',
        success : function(res) {
            var infor = res.doctor;
            var doctor_level = ["普通医师","主治医师","副主任医师","主任医师"]
            $("#doctorName").html(infor.name);
            $("#level").html(doctor_level[infor.level-1]);
            $("#department").html(infor.department);
            $("#address").html(infor.address);
            $("#information").html(infor.information);
            $("#evaluate").html("哇真是华佗啊");

            $.each(res.outcall,function(idx,obj) {
                var oc_html = "";
                if(obj.Remain > 0){
                    oc_html += "<a id='td_a' target='_blank' href='/doctor/appoint"+
                        window.location.search +
                        "&oc_id=" + obj.id + "'>" +
                        "挂号费："+obj.fee+"元" +
                        "<br>剩余："+obj.Remain + "</a>";
                }
                else{
                    oc_html += "<a id='td_a'  href=" + window.location +
                        ">挂号费："+obj.fee+"元" +
                        "<br>剩余："+obj.Remain + "</a>";
                }
                var td = $("tr[value= '"+obj.OutCallTime+"'] td[value= '"+obj.OutCallDate.Day+"']");
                td.html(oc_html);
                if(obj.Remain > 0){
                    td.attr("bgcolor","#60afff");
                }
                else{
                    td.attr("bgcolor","#d9534f");
                }
            });
        }
    });
    $("td[bgcolor='#d9534f'] a").on('click',function() {
        alert("这个时段已经预约光了！");
    })
});